package stark.app.function.castscreen;

import android.graphics.Color;

import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.hpplay.sdk.source.browse.api.LelinkServiceInfo;

import org.jetbrains.annotations.NotNull;

import stark.app.R;
import stark.app.databinding.ItemCsServiceBinding;
import stark.common.basic.adapter.BaseDBRVAdapter;

/**
 * Author：daizhongbin on 2021/9/8
 * Email：1027154338@qq.com
 * Desc:
 */
public class CastScreenServiceAdapter extends BaseDBRVAdapter<LelinkServiceInfo, ItemCsServiceBinding> {

    private int selPos = -1;

    public CastScreenServiceAdapter() {
        super(R.layout.item_cs_service, 0);
    }

    @Override
    public void onBindViewHolder(@NotNull BaseDataBindingHolder<ItemCsServiceBinding> holder, int position) {
        super.onBindViewHolder(holder, position);
        if (selPos == position) {
            holder.getDataBinding().llContainer.setBackgroundColor(Color.parseColor("#fff200"));
        } else {
            holder.getDataBinding().llContainer.setBackgroundColor(Color.parseColor("#00000000"));
        }
    }

    @Override
    protected void convert(@NotNull BaseDataBindingHolder<ItemCsServiceBinding> holder, LelinkServiceInfo serviceInfo) {
        super.convert(holder, serviceInfo);
        ItemCsServiceBinding binding = holder.getDataBinding();
        binding.tvName.setText(serviceInfo.getName());
    }

    public void setSelPos(int selPos) {
        if (this.selPos == selPos) {
            return;
        }
        this.selPos = selPos;
        notifyDataSetChanged();
    }

}
